﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;

namespace KPIS.GERP.Models.SYS
{
    [DataContract, Table("SysUserLoginMonitor")]
    public class UserLoginMonitor
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DataMember]
        public int UserLoginMonitorId { get; set; }

        [DataMember]
        public int UserId { get; set; }

        [DataMember]
        public string ClientIp { get; set; }

        [DataMember]
        public string SystemId { get; set; }

        [DataMember]
        public string UserCode { get; set; }

        [DataMember]
        public string FullName { get; set; }

        [DataMember]
        public int? PosId { get; set; }

        [DataMember]
        public string CurrentStatus { get; set; }

        [DataMember]
        public DateTime DateTimeInit { get; set; }

        [DataMember]
        public string Icon { get; set; }

        [DataMember, NotMapped]
        public Dictionary<string, string> IconsList = new Dictionary<string, string>
			{
				{"DefaultWeb", "/Content/Images/Icon/orderedList1.png"},
				{"Option2", "/Content/Images/Icon/orderedList2.png"},
				{"Option3", "/Content/Images/Icon/orderedList3.png"}
			};

        public UserLoginMonitor()
        {

        }

        public UserLoginMonitor(int userId, string clientIp, string systemId, string userCode, string fullName, int? posId, string currentStatus, string icon)
        {
            Initial(userId, clientIp, systemId, userCode, fullName, posId, currentStatus, icon);
        }

        public void Initial(int userId, string clientIp, string systemId, string userCode, string fullName, int? posId, string currentStatus, string icon)
        {
            UserId = userId;
            ClientIp = clientIp;
            SystemId = systemId;
            UserCode = userCode;
            FullName = fullName;
            PosId = posId;
            if (currentStatus != CurrentStatus)
            {
                DateTimeInit = DateTime.Now;
            }
            CurrentStatus = currentStatus;
            Icon = icon;
        }

        public void Update(string userCode, string fullName, int? posId, string currentStatus, string icon)
        {
            if (currentStatus != CurrentStatus)
            {
                DateTimeInit = DateTime.Now;
            }
            CurrentStatus = currentStatus;
            Icon = icon;
        }

        public void Update(string currentStatus, string icon)
        {
            if (currentStatus != CurrentStatus)
            {
                DateTimeInit = DateTime.Now;
            }
            CurrentStatus = currentStatus;
            Icon = icon;
        }
    }
}